package com.proj;

import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class UserMatchQueue {
    private static List<User> userList=new ArrayList<User>();
    public static void addUser(String userName){
        System.out.println("user added:"+userName);
        if(getUserByName(userName)==null)//为null说明不重名;若重名，则不操作
            userList.add(new User(userName));
    }
    private static User getUserByName(String userName){
        User user=null;
        for(int i=0;i<userList.size();i++){
            if(userList.get(i).getName().equals(userName)){
                user=userList.get(i);
                break;
            }
        }
        return user;
    }
    public static String getMatch(String userName){
        User user=getUserByName(userName);
        if(user==null)//是否有这个人
            return null;
        return GameList.add(user);
    }
    public  static String getMatchState(String userName){
        User user=getUserByName(userName);
        String msg="fail";
        if(user!=null){
            if(user.getState())msg="success";
            else msg="waiting";
        }
        return msg;//msg内容为fail，表示没有该用户
    }
}
